package java8.deom4;

import java.util.IntSummaryStatistics;
import java.util.Optional;
import java.util.stream.Stream;

import org.junit.Test;

public class Tests3  {




	
	
	@Test
	public void test1() {		
		IntSummaryStatistics intSum=Stream.of("1","2","3").mapToInt(str ->Integer.parseInt(str)).summaryStatistics();
		System. out. printf("Max: %d, Min: %d, Ave: %f, Sum: %d",
				intSum. getMax() ,
				intSum. getMin() ,
				intSum. getAverage() ,
				intSum. getSum() ) ;
	}
	

	@Test
	public void test2() {
		Optional<String> a =Optional.of("a");
		System.out.println(a.get());
		
		Optional<Integer> b=Optional.empty();
//		System.out.println(b.get());
		System.out.println("b:"+b.isPresent());
		System.out.println("b:"+b.orElse(123));
		System.out.println("b:"+b.orElseGet(() -> 234));
		
		Optional<Integer> c=Optional.ofNullable(null);
//		System.out.println(c.get());
		System.out.println("c:"+c.isPresent());
		System.out.println("c:"+c.orElse(123));
		System.out.println("c:"+c.orElseGet(() -> 234));
		
		
		Integer d=null;
		Optional<Integer> d2=Optional.ofNullable(d);
//		System.out.println(d2.get());
		System.out.println("d2:"+d2.isPresent());
		System.out.println("d2:"+d2.orElse(123));
		System.out.println("d2:"+d2.orElseGet(() -> 234));
		
		Integer e=5;
		Optional<Integer> e2=Optional.ofNullable(e);
		System.out.println("e2:"+e2.get());
		System.out.println("e2:"+e2.isPresent());
		System.out.println("e2:"+e2.orElse(123));
		System.out.println("e2:"+e2.orElseGet(() -> 234));
		
		
	}
	
	
	
	
	
	
	
	
	
}
